package com.boss.fileapp.dao.impl;

import com.boss.fileapp.consts.TableName;
import com.boss.fileapp.dao.AutoCronDao;
import com.boss.fileapp.entity.AgencyVerify;
import com.boss.framework.dao.BaseDaoImpl;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <br>Title:
 * <br>Description:
 * <br>Author:
 * <br>Date:
 */
@Repository
public class AutoCronDaoImpl extends BaseDaoImpl implements AutoCronDao {


    @Override
    public List<Map<String, Object>> getEndDay() {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT end_salary_time, mof_div_code FROM ").append(TableName.REPORT_TIME_CONTROL);
        return this.getjdbcTemplate().queryForList(sql.toString());
    }

    @Override
    public List<AgencyVerify> getNoReportAgencyData(String mofDivCode) {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" id, biz_key, create_time, update_time, agency_id, salary_month, salary_verified_in_agency_code, ")
            .append(" salary_info_verified_code, person_info_verified_code, agency_info_verified_code, is_submit_in_agency, ")
            .append(" is_salary_submit, is_person_submit, is_agency_submit, is_confirm_submit, is_month_end, is_deleted, ")
            .append(" audit_explain, remark, is_salary_change, add_person_num, add_quit_person_num, delete_person_num, ")
            .append(" is_thirteen, is_pay_data_created, is_bank_data_created, mof_div_code, year ");
        sql.append(" FROM ").append(TableName.AGENCY_VERIFY);
        sql.append(" WHERE mof_div_code = ? and is_month_end = ? and is_salary_change = ? and is_salary_submit = ? ");
        Object[] objects = new Object[] {
                mofDivCode, 0, 0, 0
        };
        return this.getjdbcTemplate().query(sql.toString(), new BeanPropertyRowMapper<>(AgencyVerify.class), objects);
    }

    @Override
    public void updateAgencyInfo(AgencyVerify agencyVerify) {
        StringBuilder sql = new StringBuilder();
        sql.append(" UPDATE ").append(TableName.AGENCY_VERIFY);
        sql.append(" SET salary_verified_in_agency_code = ?, is_submit_in_agency = ?, is_salary_submit = ?, is_auto = ? ");
        sql.append(" WHERE id = ? ");
        Object[] objects = new Object[] {
                agencyVerify.getSalaryVerifiedInAgencyCode(), agencyVerify.getIsSubmitInAgency(),
                agencyVerify.getIsSalarySubmit(), agencyVerify.getIsAuto(), agencyVerify.getId()
        };
        this.getjdbcTemplate().update(sql.toString(), objects);
    }

    @Override
    public Map<String, Object> getWorkflowNodeConfig(String mofDivCode) {
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT process_def_key, first_menu_id, user_id ");
        sql.append(" FROM ").append(TableName.WORKFLOW_AUTO_REPORT_CONFIG);
        sql.append(" WHERE mof_div_code = ? ");
        return this.getjdbcTemplate().queryForMap(sql.toString(), new Object[]{mofDivCode});
    }
}
